﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel.Composition;
using System.ComponentModel.Composition.Hosting;

namespace JQuery
{
    public class ExtensionContainer
    {
        public ExtensionContainer(AggregateCatalog catalog)
        {
            container = new CompositionContainer(catalog);

            container.ComposeParts(this);
        }

        private CompositionContainer container = null;

        [ImportMany]
        public IEnumerable<IPlugin> JQPlugins { get; set; }

        public void Compose(object obj)
        {
            container.ComposeParts(obj);
        }

        public Lazy<T> GetExport<T>(string contract)
        {
            return container.GetExport<T>(contract);
        }

        public T GetExportOrDefault<T>(string contract)
        {
            return container.GetExportedValueOrDefault<T>(contract);
        }
    }
}
